package com.xinchuang.controller;

import cn.hutool.core.lang.UUID;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xinchuang.comment.R;
import com.xinchuang.entity.api.MoldTestList;
import com.xinchuang.service.actual.SynService;
import com.xinchuang.service.apiutil.ApiUtilService;
import com.xinchuang.utils.MyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * TODO
 *
 * @author zkwczx
 * @version 1.0
 * @date 2023/10/11 20:55
 */
@RequestMapping(value = "/api")
@RestController
@RequiredArgsConstructor
@Api(value = "外部接口", tags = "外部接口")
public class ApiUtilController {

    private final ApiUtilService apiUtilService;

    private final SynService synService;

    /**
     * 获取审批通过试模通知单
     * @param moldTestList
     * @return
     */
    @ApiOperation("获取审批通过试模通知单")
    @PostMapping(value = "/getMoldTestList")
    public ResponseEntity<String> getMoldTestList(
            @RequestBody MoldTestList moldTestList
            ) {
        return apiUtilService.getMoldTestList(moldTestList);
    }

    @ApiOperation("校验token")
    @GetMapping(value = "/getUserData")
    public R getUserData(
            @RequestParam(value = "token") String token
    ) {
        return apiUtilService.getUser(token);
    }

    @ApiOperation("同步模具")
    @PostMapping(value = "/synMold")
    public R getSynMold(@RequestBody JSONObject json) {
        return synService.synMold(json);
    }

    @ApiOperation("获取OA用户")
    @PostMapping(value = "/getOAUser")
    public R getUnitUser(@RequestBody JSONObject json) {
        return apiUtilService.getUnitUser(json);
    }

    //测试接口

    @PostMapping(value = "/Auth/AuthenticateApiUser")
    public String login(@RequestBody JSONObject jsonObject) {
        return UUID.randomUUID().toString();
    }

    @GetMapping(value = "/Express/Auth/ValidateToken")
    public String validateToken(HttpServletRequest request) {
        String authorization = request.getHeader("Authorization");
        System.out.println(authorization);
        return apiUtilService.testToken();
    }

    @PostMapping(value = "/OA/Form/MouldTestingApplication/Create")
    public String createMouldTest() {
        return apiUtilService.testModelNumber();
    }

    @GetMapping(value = "/Nem/Mould/MouldInfos")
    public JSONArray MouldInfos(
            @RequestParam(value = "earliestCreateTime") String earliestCreateTime
    ) {
        String str = "[{\n" +
                "    \"mouldNumber\": \"HT-23382\",\n" +
                "    \"productName\": \"左角盖板 右角盖板\",\n" +
                "    \"projectName\": \"MMA前端模块项目\",\n" +
                "    \"projectEngineerName\": null,\n" +
                "    \"fitterTeamName\": null,\n" +
                "    \"createdAt\": \"2023-11-01T14:21:04\"\n" +
                "  },\n" +
                "  {\n" +
                "    \"mouldNumber\": \"HT-23210-G0203\",\n" +
                "    \"productName\": \"CD701A立柱上内饰板本体（左右）\",\n" +
                "    \"projectName\": \"CD701立柱、门槛项目\",\n" +
                "    \"projectEngineerName\": \"梁勇\",\n" +
                "    \"fitterTeamName\": \"钳工六组\",\n" +
                "    \"createdAt\": \"2023-11-01T16:36:44\"\n" +
                "  },\n" +
                "  {\n" +
                "    \"mouldNumber\": \"HT-23212-G0202\",\n" +
                "    \"productName\": \"CD701B立柱下内饰板本体（左右）\",\n" +
                "    \"projectName\": \"CD701立柱、门槛项目\",\n" +
                "    \"projectEngineerName\": \"梁勇\",\n" +
                "    \"fitterTeamName\": \"钳工五组\",\n" +
                "    \"createdAt\": \"2023-11-01T16:37:09\"\n" +
                "  }]";
        return JSONArray.parseArray(str);
    }

}
